import 'package:learning_content_admin_pannel.core/core/domain/entities/learning_content/lexical_item/lexical_item.dart';

int compareWordsByFrequency(Word firstWord, Word secondWord) {
  if (firstWord.rank == null && secondWord.rank == null) {
    return 0;
  }

  if (firstWord.rank != null && secondWord.rank == null) {
    return -1;
  }

  if (firstWord.rank == null && secondWord.rank != null) {
    return 1;
  }

  return firstWord.rank!.compareTo(secondWord.rank!);
}

int comparePhrasalVerbsByFrequency(PhrasalVerb firstPhrasalVerb, PhrasalVerb secondPhrasalVerb) {
  if (firstPhrasalVerb.rank == null && secondPhrasalVerb.rank == null) {
    return 0;
  }

  if (firstPhrasalVerb.rank != null && secondPhrasalVerb.rank == null) {
    return -1;
  }

  if (firstPhrasalVerb.rank == null && secondPhrasalVerb.rank != null) {
    return 1;
  }

  return firstPhrasalVerb.rank!.compareTo(secondPhrasalVerb.rank!);
}

int compareLexicalItemsTitleAlphabetically(
    LexicalItem firstLexicalItem, LexicalItem secondLexicalItem) {
  return firstLexicalItem.title.toLowerCase().compareTo(secondLexicalItem.title.toLowerCase());
}

int compareLexicalItemsByPriority(LexicalItem firstLexicalItem, LexicalItem secondLexicalItem) {
  final firstLexicalItemPriority = _getLexicalItemPriority(firstLexicalItem);
  final secondLexicalItemPriority = _getLexicalItemPriority(secondLexicalItem);

  return firstLexicalItemPriority.compareTo(secondLexicalItemPriority);
}

int _getLexicalItemPriority(LexicalItem lexicalItem) {
  switch (lexicalItem) {
    case Noun():
      return 1;
    case Adjective():
      return 2;
    case Verb():
      return 3;
    case PhrasalVerb():
      return 4;
    case Numeral():
      return 5;
    case Adverb():
      return 6;
    case Pronoun():
      return 7;
    case Conjunction():
      return 8;
    case Preposition():
      return 9;
    case UnspecifiedWord():
      return 10;
  }
}
